@namespace MduiBlazor
@inherits MduiComponentBase
@typeparam TItem
@implements ITable<TItem>
@implements ITreeTable

<table class="@Classname" style="@Style" @attributes="@AdditionalAttributes">
    <CascadingValue Value="@this" IsFixed>
        <thead>
            <MduiHeadTr @ref="@_header" TItem="@TItem">
                @if (HeaderContent is not null)
                {
                    @HeaderContent
                }
                else if (Columns is not null)
                {
                    <CascadingValue Name="RenderMode" Value="@MduiColumn.RenderMode.Head" IsFixed>
                        @Columns(DefaultValue)
                    </CascadingValue>
                }
            </MduiHeadTr>
        </thead>
        <tbody>
            @if (Items?.Any() == true && Columns != null)
            {
                <CascadingValue Name="RenderMode" Value="@MduiColumn.RenderMode.Body" IsFixed>
                    @foreach (var item in Items)
                    {
                        if (HasTreeData)
                        {
                            <MduiTreeTableNode Item="@item">
                                @Columns(item)
                            </MduiTreeTableNode>
                        }
                        else
                        {
                            <MduiTr Item="@item">
                                @Columns(item)
                            </MduiTr>
                        }
                    }
                </CascadingValue>
            }
        </tbody>
    </CascadingValue>
</table>
